home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 22 / AACD 22.iso / AACD / Sound / Subspace68k / src / Subspace68k4.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-05-04  |  52.2 KB  |  1,490 lines

  1. #define P96 //SuRgEoN :for compatibility - still through cgfx
  2.  
  3.  
  4. #ifdef __PPC__
  5. #define MAXWIDTH  640
  6. #define MAXHEIGHT 480
  7. #else
  8. #define MAXWIDTH  512
  9. #define MAXHEIGHT 384
  10. #endif
  11.  
  12. #define NUMFIELDS 19
  13. #define NUMWAVES 12
  14.  
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17. #include <string.h>
  18. #include <time.h>
  19. #include <math.h>
  20.  
  21. #include <exec/types.h>
  22. #include <exec/libraries.h>
  23. #include <exec/memory.h>
  24. #include <exec/devices.h>
  25. #include <graphics/gfx.h>
  26. #include <graphics/gfxbase.h>
  27. #include <intuition/intuition.h>
  28. #include <cybergraphics/cybergraphics.h>
  29.  
  30. #include <proto/exec.h>
  31. #include <proto/dos.h>
  32. #include <proto/intuition.h>
  33. #include <proto/graphics.h>
  34. #include <proto/cybergraphics.h>
  35. #include <proto/icon.h>
  36. #include <proto/keymap.h>
  37. #include <devices/timer.h>
  38. #include <proto/timer.h>
  39.  
  40. #include <workbench/startup.h>
  41. #include <dos/dostags.h>
  42. //#include <graphics/gfxbase.h>
  43. //#include <cybergraphx/cybergraphics.h>
  44. //#include <libraries/picasso96.h>
  45. //#include <clib/picasso96_protos.h>
  46.  
  47. #ifdef __SASC
  48. struct Library *PPCLibBase;
  49. #include <PowerUP/PPCLib/tasks.h>
  50. ULONG   PPCCallOS(struct Caos*);
  51. ULONG   PPCSetTaskAttrs(void*, struct TagItem*);
  52.  
  53. #define PPCSetTaskAttrs(TaskObject, Tags)       _PPCSetTaskAttrs(PPC_BASE_NAME, TaskObject, Tags)
  54. static __inline ULONG _PPCSetTaskAttrs(void *PPCLibBase, void*TaskObject, struct TagItem*Tags) {
  55.         struct Caos     MyCaos;
  56.         MyCaos.M68kCacheMode    =       IF_CACHEFLUSHALL;
  57.         MyCaos.PPCCacheMode     =       IF_CACHEFLUSHALL;
  58.         MyCaos.a0               =(ULONG) TaskObject;
  59.         MyCaos.a1               =(ULONG) Tags;
  60.         MyCaos.caos_Un.Offset   =       (-192);
  61.         MyCaos.a6               =(ULONG) PPCLibBase;    
  62.         return((ULONG)PPCCallOS(&MyCaos));
  63. }
  64. #endif
  65.  
  66.  
  67. #include "TrackInfo.h"
  68.  
  69. BOOL PluginInit(int argc, char **argv);
  70. void PluginExit(void);
  71. void PluginLoop(void); //mainloop for viasualization effects
  72. void ShowRequester(char *Text, char *Button);
  73. struct MsgPort *MyCreatePort(UBYTE *name, LONG pri);
  74. void MyDeletePort(struct MsgPort *mp);
  75.  
  76. /***************************************************************************/
  77. /* This is the global variables section. Don't change anything here unless */
  78. /* you know what you're doing!                                             */
  79. /***************************************************************************/
  80.  
  81. BYTE             PluginSignal, InfoSignal, ConfigSignal;
  82. ULONG            PluginMask,   InfoMask,   ConfigMask;
  83. BOOL             Accepted;
  84. struct Process   *PluginTask;
  85. struct MsgPort   *PluginMP;
  86. struct MsgPort   *PluginRP;
  87. struct TrackInfo *tinfo;
  88.  
  89. #ifdef __SASC
  90. struct Library     *TimerBase;
  91. #else
  92.  #ifdef __VBCC__ //SuRgEoN
  93. struct Library      *TimerBase = NULL;
  94.  #else
  95. struct Device      *TimerBase;
  96.  #endif
  97. #endif
  98. struct MsgPort     *TimerMP;
  99. struct timerequest *TimerIO = NULL;
  100. struct EClockVal   ev1;
  101. struct EClockVal   ev2;
  102. BYTE               TimerError = -1;
  103. ULONG              EFreq=0;
  104. ULONG              TimerMask;
  105.  
  106. UWORD   TrackInfoPos = 1;
  107.  
  108. UWORD   *PluginRawL;
  109. UWORD   *PluginRawR;
  110. WORD    *PluginSamples;
  111. UWORD   *SpecRawL;
  112. UWORD   *SpecRawR;
  113. WORD *SampleRaw;
  114.  
  115. struct PluginMessage {
  116.         struct Message   msg;
  117.         ULONG            PluginMask;
  118.         struct Process   *PluginTask;
  119.         UWORD            **SpecRawL;
  120.         UWORD            **SpecRawR;
  121.         UWORD            Accepted;
  122.         UWORD            reserved0;
  123.         ULONG            InfoMask;
  124.         struct TrackInfo **tinfo;
  125.         ULONG            ConfigMask;
  126.         WORD             **SampleRaw;
  127. };
  128.  
  129. BOOL OpenTimer(void);
  130. void CloseTimer(void);
  131. void StartTimer(void);
  132.  
  133. /***************************************************************************/
  134. /* This is the main part. Again, don't change anything here if you haven't */
  135. /* got a very good reason to do so!                                        */
  136. /***************************************************************************/
  137.  
  138. int main(int argc, char **argv) {
  139.         struct PluginMessage *PluginMsg;
  140.         struct PluginMessage *ReplyMsg;
  141.  
  142.  
  143.         /* Allocate all user resources */
  144.         if(PluginInit(argc, argv)) {
  145.                 /* Check if a plugin capable instance of AmigaAMP is running */
  146.                 if(PluginMP=FindPort("AmigaAMP plugin port"))   {
  147.                         /* Allocate some sigbits for receiving signals FROM AmigaAMP */
  148.                         PluginSignal = AllocSignal(-1);
  149.                         ConfigSignal = AllocSignal(-1);
  150.                         InfoSignal   = AllocSignal(-1);
  151.                         PluginTask   = (struct Process *)FindTask(NULL);
  152.  
  153.                         if(PluginSignal != -1 && InfoSignal != -1 && PluginSignal != -1) {
  154.                                 PluginMask = 1L << PluginSignal;
  155.                                 ConfigMask = 1L << ConfigSignal;
  156.                                 InfoMask   = 1L << InfoSignal;
  157.  
  158.                                 /* Allocate a message and reply port for sending messages TO AmigaAMP */
  159.                                 #if defined (__SASC) || defined (__VBCC__) //SuRgEoN
  160. #ifdef __PPC__
  161.                                 PluginMsg=PPCAllocVec(sizeof(struct PluginMessage), MEMF_PUBLIC|MEMF_CLEAR);
  162. #else
  163.                                 PluginMsg=AllocVec(sizeof(struct PluginMessage), MEMF_PUBLIC|MEMF_CLEAR);
  164. #endif
  165.                                 PluginRP=(struct MsgPort*)MyCreatePort(0,0);
  166.                                 #else
  167.                                 PluginMsg=AllocVecPPC(sizeof(struct PluginMessage), MEMF_PUBLIC|MEMF_CLEAR, 0);
  168.  
  169.                                 PluginRP=(struct MsgPort*)CreatePort(0,0);
  170.                                 #endif
  171.  
  172.                                 /* Tell AmigaAMP all the details it needs to know */
  173.                                 PluginMsg->msg.mn_Node.ln_Type = NT_MESSAGE;
  174.                                 PluginMsg->msg.mn_Length       = sizeof(struct PluginMessage);
  175.                                 PluginMsg->msg.mn_ReplyPort    = PluginRP;
  176.                                 PluginMsg->PluginMask          = PluginMask;
  177.                                 PluginMsg->PluginTask          = PluginTask;
  178.                                 PluginMsg->SpecRawL            = &SpecRawL;
  179.                                 PluginMsg->SpecRawR            = &SpecRawR;
  180.                                 PluginMsg->InfoMask            = InfoMask;
  181.                                 PluginMsg->tinfo               = &tinfo;
  182.                                 PluginMsg->ConfigMask          = ConfigMask;
  183.                                 PluginMsg->SampleRaw           = &SampleRaw;
  184.                                 PutMsg(PluginMP, (struct Message *)PluginMsg);
  185.                                 /* Wait for a reply */
  186.                                 WaitPort(PluginRP);
  187.                                 /* Let's see if AmigaAMP accepted our registration attempt */
  188.                                 if(ReplyMsg = (struct PluginMessage *)GetMsg(PluginRP)) Accepted=ReplyMsg->Accepted;
  189.                                 else Accepted=FALSE;
  190.  
  191.                                 if(Accepted) {
  192.                                         /* If it did, start the plugin loop */
  193.                                         printf("Init ok! - entering plugin loop\n");
  194.                                         PluginLoop();
  195.  
  196.                                         /* Tell AmigaAMP that this plugin is going down */
  197.                                         PluginMsg->PluginMask          = 0;
  198.                                         PluginMsg->PluginTask          = NULL;
  199.                                         PluginMsg->SpecRawL            = NULL;
  200.                                         PluginMsg->SpecRawR            = NULL;
  201.                                         PluginMsg->ConfigMask          = 0;
  202.                                         PluginMsg->InfoMask            = 0;
  203.                                         PluginMsg->tinfo               = NULL;
  204.                                         PluginMsg->SampleRaw           = NULL;
  205.                                         PutMsg(PluginMP, (struct Message *)PluginMsg);
  206.                                         /* Wait for confirmation before going on! */
  207.                                         WaitPort(PluginRP);
  208.                                         GetMsg(PluginRP);
  209.                                         /* Now that AmigaAMP knows that we're gone, we can quit */
  210.                                 }
  211.                                 else {
  212.                                         /* If AmigaAMP didn't accept us, tell the user about it */
  213.                                         ShowRequester("Plugin rejected by AmigaAMP!\nPerhaps there's another one running.", "Abort");
  214.                                 }
  215.  
  216.                                 /* Free all resources */
  217.                                 #ifdef __SASC
  218.  
  219.                                         PPCFreeVec(PluginMsg);
  220.                                         MyDeletePort(PluginRP);
  221.                                 #else
  222.                                         #ifndef PPC__ //SuRgEoN
  223.                                         FreeVec(PluginMsg);
  224.                                         DeletePort(PluginRP);
  225.                                         #else
  226.                                         FreeVecPPC(PluginMsg);
  227.                                         DeletePort(PluginRP);
  228.                                         #endif
  229.                                 #endif
  230.                         }
  231.                         else {
  232.                                 ShowRequester("Signal allocation failure!", "Abort");
  233.                         }
  234.                         if(PluginSignal != -1) FreeSignal(PluginSignal);
  235.                         if(ConfigSignal != -1) FreeSignal(ConfigSignal);
  236.                         if(InfoSignal   != -1) FreeSignal(InfoSignal);
  237.                 }
  238.                 else {
  239.                         ShowRequester("Could not find message port!\nAmigaAMP probably not running.", "Abort");
  240.                 }
  241.         }
  242.         else {
  243.                 ShowRequester("Plugin initialisation failed!", "Ok");
  244.         }
  245.         /* Free all user resources */
  246.         PluginExit();
  247. }
  248.  
  249. /*****************************************************************************/
  250. /* Ok, now for the individual plugin sourcecode. Everything below should be  */
  251. /* changed to your needs.                                                    */
  252. /* Just like before, we start with the global variables section              */
  253. /*****************************************************************************/
  254.  
  255. void InitWave(UBYTE WaveNum, ULONG BufNum);
  256. void CalcWave(UBYTE WaveNum, ULONG BufNum);
  257. void DrawWave(LONG *WaveX, LONG *WaveY, ULONG Width, ULONG Height, UBYTE WaveNum, ULONG BufNum);
  258.  
  259. void InitField(LONG *Zoom, ULONG Width, ULONG Height);
  260. void PrepareConstants(UBYTE FieldNum);
  261. void CalcLine(LONG *Zoom, ULONG Width, ULONG Height, UBYTE FieldNum);
  262. void MakeCMap(void);
  263. void Blur(UBYTE *PixelC, UBYTE *PixelD);
  264. void ReColor(void);
  265. void MakeTitle(void);
  266. float rnd(float max);
  267. float sgn(float val);
  268.  
  269. const char VersionString[]="\0$VER: Subspace68k 1.0 (14.03.01)";
  270. const char Line1[]="Subspace";
  271. const char Line2[]="by Thomas Wenzel";
  272.  
  273. #define PRECISION PRECISION_EXACT
  274.  
  275. struct IntuitionBase *IntuitionBase = NULL;
  276. struct GfxBase *GfxBase      = NULL;
  277. struct Library *IconBase     = NULL;
  278. struct Library *KeymapBase   = NULL;
  279. struct Library *AslBase      = NULL;
  280. struct Library *GadToolsBase = NULL;
  281. struct Library *CyberGfxBase = NULL;
  282. struct Library *P96Base = NULL;
  283. struct Screen  *PluginScreen = NULL;
  284. struct Window  *PluginWin    = NULL;
  285. struct RastPort *rp;
  286. struct ViewPort *vp;
  287.  
  288.  
  289. struct EClockVal ev1;
  290. struct EClockVal ev2;
  291.  
  292.  
  293. ULONG ModeID;
  294. ULONG WinMask;
  295.  
  296. UBYTE *PixelD;
  297. UBYTE *PixelC;
  298. ULONG *Colour;
  299.  
  300. UWORD *EmptyPointer;
  301.  
  302. char InfoLine[256];
  303.  
  304. LONG Zoom[MAXWIDTH*MAXHEIGHT];
  305. LONG Zoom2[MAXWIDTH*MAXHEIGHT];
  306. LONG WaveX[MAXWIDTH*2];
  307. LONG WaveY[MAXWIDTH*2];
  308. LONG WaveX2[MAXWIDTH*2];
  309. LONG WaveY2[MAXWIDTH*2];
  310.  
  311. ULONG MidR[4], MidG[4], MidB[4];
  312. ULONG DisplayFPS;
  313. ULONG ShowWave;
  314. ULONG LimitFPS;
  315. #ifdef __PPC__
  316. ULONG ScreenSize = 100;
  317. #else
  318. ULONG ScreenSize = 85;
  319. #endif
  320. #ifdef PPC
  321. ULONG Width      = 320;
  322. ULONG Height     = 240;
  323. ULONG HalfHeight = 120;
  324. #else
  325. ULONG Width      = 288; //256*192    60, 256, 170
  326. ULONG Height     = 200; //120 with ScreenSize 80!
  327. ULONG HalfHeight = 100;
  328. #endif
  329. #ifndef __PPC__
  330. ULONG Woffset     = 16;// 32 for width 256
  331. #else
  332. ULONG Woffset     = 0;
  333. #endif
  334.  
  335. ULONG Cutoff     = 1;
  336. ULONG InfoCount;
  337. ULONG FrameCountLow;
  338. ULONG FrameCountHigh;
  339. ULONG FrameCountWave;
  340. ULONG FrameCountField;
  341. ULONG TimeWave;
  342. ULONG DestWaveNum;
  343. ULONG DestWaveBuffer;
  344. float WaveMorph;
  345. ULONG MidRdst[3], MidGdst[3], MidBdst[3];
  346. ULONG LineToCalc;
  347. UBYTE FieldToCalc;
  348. UBYTE WaveToCalc, WaveToCalc0, WaveToCalc1;
  349. UBYTE PrevField;
  350.  
  351. /****************************************************************************/
  352. /* This function will be called once when the plugin is started. You should */
  353. /* allocate all needed resources here. Return TRUE if all went well.        */
  354. /****************************************************************************/
  355.  
  356. BOOL PluginInit(int argc, char **argv) {
  357.         long i,xs,ys,xd,yd,ysp,ydp;
  358.         float xf,yf;
  359.         UBYTE **ttypes = 0; //VBCC
  360.         char *str;
  361.         struct DiskObject *IconObj = NULL; //VBCC
  362.         struct WBStartup  *WBStart = NULL; //VBCC
  363.         #ifdef __SASC
  364.         void *ThisTask;
  365.         #else
  366.         struct TaskPPC *ThisTask;
  367.         #endif
  368.         WORD Length;
  369.  
  370.   char *module = "CGfx_Init: ";
  371.   static short ColorModel[] = {PIXFMT_LUT8,-1};
  372.  
  373. #ifdef __PPC__
  374.         struct TagItem ModeIDtags[] = {
  375.                 CYBRBIDTG_Depth, 8, CYBRBIDTG_NominalWidth, 320, CYBRBIDTG_NominalHeight, 240, TAG_DONE};
  376. #else
  377.         struct TagItem ModeIDtags[] = {
  378.                 CYBRBIDTG_Depth, 8, CYBRBIDTG_NominalWidth, 320, CYBRBIDTG_NominalHeight, 200, TAG_DONE};
  379. /*
  380.         struct TagItem ModeIDtags[] = {CYBRMREQ_MinWidth, 320,  CYBRMREQ_MinHeight, 200, CYBRMREQ_MaxHeight, 240, TAG_DONE};
  381. */
  382.  
  383. #endif
  384.         AslBase=OpenLibrary("asl.library", 0);
  385.         if(!AslBase) {
  386.                 ShowRequester("Can't open asl.library!", "Abort");
  387.                 return(FALSE);
  388.         }
  389.  
  390.         IconBase=OpenLibrary("icon.library", 0);
  391.         if(!IconBase) {
  392.                 ShowRequester("Can't open icon.library!", "Abort");
  393.                 return(FALSE);
  394.         }
  395.  
  396.         KeymapBase=OpenLibrary("keymap.library", 0);
  397.         if(!KeymapBase) {
  398.                 ShowRequester("Can't open keymap.library!", "Abort");
  399.                 return(FALSE);
  400.         }
  401.  
  402.         IntuitionBase=(struct IntuitionBase*)OpenLibrary("intuition.library", 0);
  403.         if(!IntuitionBase) {
  404.                 ShowRequester("Can't open intuition.library!", "Abort");
  405.                 return(FALSE);
  406.         }
  407.  
  408.         GadToolsBase=OpenLibrary("gadtools.library", 0);
  409.         if(!GadToolsBase) {
  410.                 ShowRequester("Can't open gadtools.library!", "Abort");
  411.                 return(FALSE);
  412.         }
  413.  
  414.         if(!(GfxBase= (struct GfxBase*) OpenLibrary("graphics.library", 0)))
  415.        {
  416.                 ShowRequester("Can't open graphics.library!", "Abort");
  417.                 return(FALSE);
  418.         }
  419.  
  420.         if(GfxBase->LibNode.lib_Version < 39) {
  421.                 ShowRequester("This plugin requires AmigaOS 3.0 or greater!", "Abort");
  422.                 return(FALSE);
  423.         }
  424.         if (!(CyberGfxBase = (struct Library *) OpenLibrary("cybergraphics.library", 0)))
  425.        {
  426.                 ShowRequester("This plugin requires CyberGraphX v3 or higher!", "Abort");
  427.                 return(FALSE);
  428.         }
  429.  
  430.       P96Base = (struct Library *) OpenLibrary("Picasso96API.library",0);
  431.         if(!P96Base) {
  432.                 ShowRequester("This plugin requires Picasso96", "Abort");
  433.                 return(FALSE);
  434.         }
  435.  
  436.         #ifdef __SASC
  437.                 /* Increase the priority of the 68k mirror task */
  438.                 SetTaskPri(FindTask(NULL), 15);
  439.                 /* Increase our own priority (if it only would work...) */
  440.                 PPCSetTaskAttr(PPCTASKTAG_PRIORITY, 15);
  441.         #else
  442.                 #ifdef __VBCC__
  443.         //              SetTaskPri(FindTask(NULL), 15);
  444.                 #else
  445.                 /* Increase our own priority */
  446.                 ThisTask = FindTaskPPC(NULL);
  447.                 SetNiceValue(ThisTask, -15);
  448.                 #endif
  449.         #endif
  450.  
  451.         WBStart=(struct WBStartup *)argv;
  452.  
  453. // if(argc==0) printf("IconName: %s\n", WBStart->sm_ArgList[0].wa_Name);
  454.  
  455.         if(argc==0) IconObj=GetDiskObject(WBStart->sm_ArgList[0].wa_Name);
  456.         else        IconObj=GetDiskObject(argv[0]);
  457.  
  458.         LimitFPS = 999;
  459.  
  460.         if(IconObj) {
  461.                 if(str=FindToolType(IconObj->do_ToolTypes,"MAXFPS"))
  462.                 {
  463.                         LimitFPS = atol(str);
  464.                 }
  465.  
  466.                 if(str=FindToolType(IconObj->do_ToolTypes,"RESOLUTION"))
  467.                 {
  468.                         if(stricmp(str,"high") == 0) {
  469.                                 Width      = 640;
  470.                                 Height     = 480;
  471.                                 ScreenSize = 66;
  472.                         }
  473.                         else {
  474. #ifdef __PPC__
  475.                                 Width      = 320;
  476.                                 Height     = 240;
  477.                                 ScreenSize = 100;
  478. #else
  479.                                 Width      = 288;
  480.                                 Height     = 200;
  481.                                 ScreenSize = 85;
  482. #endif
  483.  
  484.                         }
  485.                 }
  486.  
  487.                 if(str=FindToolType(IconObj->do_ToolTypes,"SCREENSIZE"))
  488.                 {
  489.                         ScreenSize = atol(str);
  490.                 }
  491.         FreeDiskObject(IconObj);
  492.         }
  493.  
  494.         if(ttypes=(UBYTE**)ArgArrayInit(argc, argv)) {
  495.                 str=(char*)ArgString(ttypes, "MAXFPS", "0");
  496.                 LimitFPS = atol(str);
  497.  
  498.                 str=(char*)ArgString(ttypes, "RESOLUTION", "low");
  499.                 if(stricmp(str,"high") == 0) {
  500.                         Width      = 640;
  501.                         Height     = 480;
  502.                         ScreenSize = 66;
  503.                         ShowWave   = 1;
  504.                 }
  505.                 else {
  506. #ifdef __PPC__
  507.                         Width      = 320;
  508.                         Height     = 240;
  509.                         ScreenSize = 100;
  510. #else
  511.                         Width      = 288; //240
  512.                         Height     = 200; //190
  513.                         ScreenSize = 85;//60
  514. #endif
  515.                         ShowWave   = 0;
  516.                 }
  517.  
  518.                 if(str=(char*)ArgString(ttypes, "SCREENSIZE", NULL)) {
  519.                         ScreenSize = atol(str);
  520.                 }
  521.  
  522.                 ArgArrayDone();
  523.         }
  524. #ifndef PPC
  525.         if(LimitFPS == 0)  LimitFPS = 999;
  526.         if(LimitFPS > 999) LimitFPS = 999;
  527. #else
  528.     LimitFPS = 10;
  529. #endif
  530.         if(ScreenSize <  25) ScreenSize =  25;
  531.         if(ScreenSize > 100) ScreenSize = 100;
  532.  
  533.         Cutoff = Height * (100-ScreenSize) / 200;
  534.         if(Cutoff <   1) Cutoff =   1;
  535.         if(Cutoff > 200) Cutoff = 200;
  536.  
  537.         ModeIDtags[1].ti_Data = Width;
  538.         ModeIDtags[2].ti_Data = Height;
  539.  
  540.         HalfHeight = Height/2;
  541.  
  542.         #if defined (__SASC) || defined (__VBCC__)
  543.                 #ifdef __PPC__
  544.                 PixelD       = PPCAllocVec(Width*Height, MEMF_PUBLIC|MEMF_CLEAR);
  545.                 PixelC       = PPCAllocVec(Width*Height, MEMF_PUBLIC|MEMF_CLEAR);
  546.                 Colour       = PPCAllocVec(770*4,        MEMF_PUBLIC|MEMF_CLEAR);
  547.                 EmptyPointer = PPCAllocVec(512,          MEMF_CHIP|MEMF_CLEAR);
  548.                 #else //68k
  549.                 PixelD       = AllocVec(Width*Height, MEMF_PUBLIC|MEMF_CLEAR);
  550.                 PixelC       = AllocVec(Width*Height, MEMF_PUBLIC|MEMF_CLEAR);
  551.                 Colour       = AllocVec(770*4,        MEMF_PUBLIC|MEMF_CLEAR);
  552.                 EmptyPointer = AllocVec(512,          MEMF_CHIP|MEMF_CLEAR);
  553.                 #endif
  554.         #else
  555.                 PixelD       = AllocVecPPC(Width*Height, MEMF_PUBLIC|MEMF_CLEAR, 0);
  556.                 PixelC       = AllocVecPPC(Width*Height, MEMF_PUBLIC|MEMF_CLEAR, 0);
  557.                 Colour       = AllocVecPPC(770*4,        MEMF_PUBLIC|MEMF_CLEAR, 0);
  558.                 EmptyPointer = AllocVecPPC(512,          MEMF_CHIP|MEMF_CLEAR,   0);
  559.         #endif
  560.  
  561.         OpenTimer();
  562.  
  563.         if(PixelD==NULL || PixelC==NULL) {
  564.                 ShowRequester("Out of memory for graphics buffers!", "Abort");
  565.                 return(FALSE);
  566.         }
  567.  
  568.         srand(time(NULL));
  569.  
  570.         MidR[0] = 230;
  571.         MidG[0] = 230;
  572.         MidB[0] = 230;
  573.  
  574.         MidR[1] = 86;
  575.         MidG[1] = 86;
  576.         MidB[1] = 170;
  577.  
  578.         MidR[2] = 25;
  579.         MidG[2] = 25;
  580.         MidB[2] = 100;
  581.  
  582.         MidR[3] = 0;
  583.         MidG[3] = 0;
  584.         MidB[3] = 0;
  585.  
  586.         MidRdst[0] = (UBYTE)(rand()>>25) + 127;
  587.         MidGdst[0] = (UBYTE)(rand()>>25) + 127;
  588.         MidBdst[0] = (UBYTE)(rand()>>25) + 127;
  589.  
  590.         MidRdst[1] = (UBYTE)(rand()>>25) + 96;
  591.         MidGdst[1] = (UBYTE)(rand()>>25) + 96;
  592.         MidBdst[1] = (UBYTE)(rand()>>25) + 96;
  593.  
  594.         MidRdst[2] = (UBYTE)(rand()>>25) + 64;
  595.         MidGdst[2] = (UBYTE)(rand()>>25) + 64;
  596.         MidBdst[2] = (UBYTE)(rand()>>25) + 64;
  597.  
  598.         DisplayFPS      = 0;
  599.         InfoCount       = 0;
  600.         FrameCountLow   = 0;
  601.         FrameCountHigh  = 0;
  602.         FrameCountWave  = 0;
  603.         FrameCountField = 0;
  604.         TimeWave        = 0;
  605.         DestWaveNum     = 1;
  606.         DestWaveBuffer  = 1;
  607.         WaveMorph       = 0.0;
  608.         LineToCalc      = 0;
  609.         WaveToCalc      = 0;
  610.         WaveToCalc0     = 0;
  611.  
  612.         FieldToCalc     = (UBYTE)(rand() % NUMFIELDS);
  613.         WaveToCalc1     = (UBYTE)(rand() % NUMWAVES);
  614.  
  615. //      FieldToCalc   = 0; //10=endblur;16=radial;2=tunnel
  616. //      WaveToCalc1   = 1;
  617. //1=tunnel;2=lines;3=radar;4=flower;5=solsweep;6=xx;7=chaoticlines;8=circwaves;9=occludinglines;10=quad;11=;
  618. //      FieldToCalc   = NUMFIELDS-1;
  619. //      WaveToCalc1   = NUMWAVES-1;
  620.  
  621.  
  622.         PrepareConstants(FieldToCalc);
  623.  
  624.         MakeCMap();
  625.  
  626. #ifdef P96
  627. /*
  628.   if (!(ModeID = CModeRequestTagList(NULL, ModeIDtags)))
  629.   {
  630.     ShowRequester("Can't open the screenmode requester", module);
  631.     return(FALSE);
  632.   }
  633.  
  634.   if (ModeID == INVALID_ID)
  635.   {
  636.     ShowRequester("Screenmode requester aborted",module);
  637.     return(FALSE);
  638.   }
  639. */
  640. //      ModeID=CModeRequestTagList(NULL, ModeIDtags);
  641.         ModeID=p96RequestModeIDTagList(ModeIDtags);
  642. #else
  643.         ModeID=BestCModeIDTagList(NULL, ModeIDtags);
  644. #endif
  645.         if(ModeID == INVALID_ID) {
  646.                 ShowRequester("Could not find suitable screen mode!", "Abort");
  647.                 return(FALSE);
  648.         }
  649.         
  650.  
  651.         PluginScreen=OpenScreenTags(NULL, SA_DisplayID, ModeID, SA_Depth, 8, SA_Width, Width, SA_Height, Height, SA_SharePens, TRUE, SA_ShowTitle, FALSE, SA_Quiet, TRUE, TAG_DONE);
  652.         if(PluginScreen == NULL) {
  653.                 ShowRequester("Could not open screen!", "Abort");
  654.                 return(FALSE);
  655.         }
  656.         rp = &PluginScreen->RastPort;
  657.         vp = &PluginScreen->ViewPort;
  658.  
  659.         LoadRGB32(vp, Colour);
  660.  
  661.         PluginWin=OpenWindowTags(NULL, WA_CustomScreen, (ULONG)PluginScreen,
  662.                                        WA_Left,         0,
  663.                                        WA_Top,          0,
  664.                                        WA_Width,        Width,
  665.                                        WA_Height,       Height,
  666.                                        WA_SizeGadget,   FALSE,
  667.                                        WA_DragBar,      FALSE,
  668.                                        WA_DepthGadget,  FALSE,
  669.                                        WA_CloseGadget,  FALSE,
  670.                                        WA_Backdrop,     TRUE,
  671.                                        WA_Borderless,   TRUE,
  672.                                        WA_Activate,     TRUE,
  673.                                        WA_AutoAdjust,   TRUE,  // Just to be sure :-)
  674.                                        WA_IDCMP,        IDCMP_RAWKEY | IDCMP_ACTIVEWINDOW | IDCMP_INACTIVEWINDOW,
  675.                                        TAG_DONE);
  676.         if(PluginWin == NULL) {
  677.                 ShowRequester("Could not open window!", "Abort");
  678.                 return(FALSE);
  679.         }
  680.  
  681.         SetPointer(PluginWin, EmptyPointer, 1, 1, 0, 0);
  682.         SetAPen(rp, 1);
  683.         RectFill(rp, 0, 0, (Width-1), (Height-1));
  684.         SetAPen(rp, 255);
  685.  
  686.         WinMask = 1L << PluginWin->UserPort->mp_SigBit;
  687.  
  688.         InitField(Zoom, Width, Height);
  689.         MakeTitle();
  690.  
  691.         return(TRUE);
  692. }
  693.  
  694. /******************************************************************************/
  695. /* This function will be called when the plugin is shut down. You should free */
  696. /* all previously allocated resources here.                                   */
  697. /******************************************************************************/
  698.  
  699. void PluginExit(void) {
  700.         long i;
  701.  
  702.         if(PluginWin)    CloseWindow(PluginWin);
  703.         if(PluginScreen) CloseScreen(PluginScreen);
  704.         #ifdef __SASC
  705.                 if(PixelD)       PPCFreeVec(PixelD);
  706.                 if(PixelC)       PPCFreeVec(PixelC);
  707.                 if(Colour)       PPCFreeVec(Colour);
  708.                 if(EmptyPointer) PPCFreeVec(EmptyPointer);
  709.         #else
  710.          #ifdef __PPC__ 
  711.                 if(PixelD)       FreeVecPPC(PixelD);
  712.                 if(PixelC)       FreeVecPPC(PixelC);
  713.                 if(Colour)       FreeVecPPC(Colour);
  714.                 if(EmptyPointer) FreeVecPPC(EmptyPointer);
  715.          #else
  716.                 if(PixelD)       FreeVec(PixelD);
  717.                 if(PixelC)       FreeVec(PixelC);
  718.                 if(Colour)       FreeVec(Colour);
  719.                 if(EmptyPointer) FreeVec(EmptyPointer);
  720.          #endif
  721.         #endif
  722.  
  723.         CloseTimer();
  724.         if(CyberGfxBase)  CloseLibrary(CyberGfxBase);
  725.         if(P96Base)    CloseLibrary(P96Base);
  726. //      if(GfxBase)       CloseLibrary(GfxBase);
  727.         if(AslBase)       CloseLibrary(AslBase);
  728.         if(IconBase)      CloseLibrary(IconBase);
  729.         if(KeymapBase)    CloseLibrary(KeymapBase);
  730.         if(GadToolsBase)  CloseLibrary(GadToolsBase);
  731. //      if(IntuitionBase) CloseLibrary(IntuitionBase);
  732. }
  733.  
  734. /*******************************************************************************/
  735. /* This is the main Plugin Loop. It will receive a signal matching PluginMask  */
  736. /* each time new spectral data is ready. The data is stored in two arrays,     */
  737. /* UWORD Spec[512] in structures DataL and DataR. The scale is logarithmic,    */
  738. /* 0 means below -96dB, 65535 means 0dB.                                       */
  739. /* No matter how long it takes until your plugin actually processes the data,  */
  740. /* the memory referenced by the array pointers always remains valid!           */
  741. /*                                                                             */
  742. /* Your plugin loop MUST quit when it receives SIGBREAKF_CTRL_C. If you've     */
  743. /* opened a window you should react to the close gadget as well. For full      */
  744. /* screen plugins I strongly recommend checking the ESC key.                   */
  745. /*******************************************************************************/
  746.  
  747. void PluginLoop(void) {
  748.         struct TextExtent te;
  749.         ULONG *PixelL = 0;
  750.         UBYTE *ActPixel;
  751.         ULONG Signals = 0;
  752.         LONG i,j,k;
  753.         LONG l,r;
  754.         LONG x,y;
  755.         UBYTE v;
  756.         UWORD w;
  757.         UBYTE ColorMode;
  758.  
  759.         ULONG   hi,lo,itime,eclock;
  760.         char FPStext[64];
  761.  
  762.         UBYTE Vanilla;
  763.         struct InputEvent ie;
  764.         WORD    RawLen;
  765.         printf("entering main loop\n");
  766.         Wait(SIGBREAKF_CTRL_C | PluginMask);
  767.  
  768.         /* Make a backup of the data pointers */
  769.         PluginRawL    = SpecRawL;
  770.         PluginRawR    = SpecRawR;
  771.         PluginSamples = SampleRaw;
  772.         WritePixelArray(PixelC, 0, 0, Width, rp, Woffset, 0, Width, Height, RECTFMT_LUT8);
  773.         Delay(100);
  774.  
  775.         StartTimer();
  776.  
  777.         InitWave(WaveToCalc0, 0);
  778.         InitWave(WaveToCalc1, 1);
  779.  
  780.         for(;;) {
  781.                 /* Wait until there's something to do */
  782.  
  783.                 Signals=Wait(SIGBREAKF_CTRL_C | PluginMask | ConfigMask | InfoMask | WinMask | TimerMask);
  784.                 if(Signals & TimerMask) {
  785.                         WaitIO((struct IORequest *) TimerIO);
  786.                 }
  787.  
  788.                 /* Break received -> quit at once! */
  789.                 if(Signals & SIGBREAKF_CTRL_C) break;
  790.  
  791.                 /* Window close gadget hit -> quit as well! */
  792.                 if(Signals & WinMask) {
  793.                         struct IntuiMessage *imsg;
  794.                         BOOL done=0;
  795.  
  796.                         while(imsg=(struct IntuiMessage *)GetMsg(PluginWin->UserPort)) {
  797.                                 if(imsg->Class == IDCMP_RAWKEY) {
  798.                                         ie.ie_Class        = IECLASS_RAWKEY;
  799.                                         ie.ie_SubClass     = 0;
  800.                                         ie.ie_Code         = imsg->Code;
  801.                                         ie.ie_Qualifier    = 0;
  802.                                         ie.ie_EventAddress = imsg->IAddress;
  803.                                         RawLen = MapRawKey(&ie, &Vanilla, 1, 0);
  804.  
  805.                                         switch(imsg->Code) {
  806.                                                 case 0x45: done=1; break;
  807.                                         }
  808.  
  809.                                         if(RawLen==1) {
  810.                                                 switch(Vanilla) {
  811.                                                         case 'f': DisplayFPS = 1-DisplayFPS; break;
  812.                                                         case 'w': ShowWave   = 1-ShowWave;   break;
  813.                                                         case 'i': InfoCount  = 0;            break;
  814. //                                              case '+': Cutoff--;                  break;
  815. //                                              case '-': Cutoff++;                  break;
  816.                                                 }
  817.                                                 if(Cutoff < 1) Cutoff =   1;
  818.                                                 if(Cutoff > HalfHeight-10) Cutoff = HalfHeight-10;
  819.                                                 for(i=0; i<Width*Cutoff; i++) {
  820.                                                         PixelC[i]=PixelD[i]=0;
  821.                                                 }
  822.                                                 for(i=Width*(Height-Cutoff); i<Width*Height; i++) {
  823.                                                         PixelC[i]=PixelD[i]=0;
  824.                                                 }
  825.                                         }
  826.                                 }
  827.                                 ReplyMsg(imsg);
  828.                         }
  829.                         if(done) break;
  830.                 }
  831.  
  832.                 if(Signals & TimerMask) {
  833.                         StartTimer();
  834. //printf("timer started\n");
  835.       Blur(PixelC, PixelD);
  836.  
  837.                         FrameCountLow++;
  838.                         if(FrameCountLow > 4) {
  839.                                 FrameCountLow = 0;
  840.                                 eclock=ReadEClock(&ev2);
  841.                                 hi = ev2.ev_hi - ev1.ev_hi;
  842.                                 lo = ev2.ev_lo - ev1.ev_lo;
  843.                                 itime = hi*eclock+lo;
  844.  
  845.                                 if(itime==0) itime=1;
  846.  
  847.                                 ev1.ev_hi = ev2.ev_hi;
  848.                                 ev1.ev_lo = ev2.ev_lo;
  849.                                 ReColor();
  850.                         }
  851.  
  852.                         FrameCountHigh++;
  853.                 if(FrameCountHigh > 600) {
  854.                                 FrameCountHigh = 0;
  855. #ifndef __VBCC__
  856.                                 ColorMode = (UBYTE)(rand()>>24) % 10;
  857.  
  858. #else
  859. /*
  860. if(ColorMode==0)
  861. {
  862.         MidR[0] = 255;
  863.         MidG[0] = 220;
  864.         MidB[0] = 200;
  865.  
  866.         MidR[1] = 170;
  867.         MidG[1] = 96;
  868.         MidB[1] = 170;
  869.  
  870.         MidR[2] = 10;
  871.         MidG[2] = 100;
  872.         MidB[2] = 52;
  873.  
  874. ColorMode=1;
  875. }
  876. */
  877. /*
  878. if(ColorMode==0)
  879. {
  880.         MidR[0] = 255;
  881.         MidG[0] = 200;
  882.         MidB[0] = 255;
  883.  
  884.         MidR[1] = 96;
  885.         MidG[1] = 76;
  886.         MidB[1] = 178;
  887.  
  888.         MidR[2] = 100;
  889.         MidG[2] = 55;
  890.         MidB[2] = 65;
  891.  
  892. ColorMode=1;
  893. }
  894. */
  895.  
  896. if(ColorMode == 0)
  897. {
  898. //blue
  899.         MidR[0] = 230;
  900.         MidG[0] = 230;
  901.         MidB[0] = 230;
  902.  
  903.         MidR[1] = 86;
  904.         MidG[1] = 86;
  905.         MidB[1] = 170;
  906.  
  907.         MidR[2] = 25;
  908.         MidG[2] = 25;
  909.         MidB[2] = 100;
  910.  
  911. ColorMode = 1;
  912. }
  913. else
  914. {
  915. //fire
  916.         MidR[0] = 255;
  917.         MidG[0] = 255;
  918.         MidB[0] = 100;
  919.  
  920.         MidR[1] = 200;
  921.         MidG[1] = 120;
  922.         MidB[1] = 10;
  923.  
  924.         MidR[2] = 100;
  925.         MidG[2] = 25;
  926.         MidB[2] = 25;
  927.  
  928.         MidR[3] = 0;
  929.         MidG[3] = 0;
  930.         MidB[3] = 0;
  931.  
  932. ColorMode = 0;
  933. }
  934.  
  935. #endif
  936.                         printf("ColorMode: %d\n", ColorMode);
  937. #ifndef __VBCC__
  938.                                 switch(ColorMode) {
  939.                                         case 0:
  940.                                         case 1:
  941.                                                 MidRdst[0] = (UBYTE)(rand()>>25) + 127;
  942.                                                 MidGdst[0] = (UBYTE)(rand()>>25) + 127;
  943.                                                 MidBdst[0] = (UBYTE)(rand()>>25) + 127;
  944.  
  945.                                                 MidRdst[1] = (UBYTE)(rand()>>24) + 0;
  946.                                                 MidGdst[1] = (UBYTE)(rand()>>24) + 0;
  947.                                                 MidBdst[1] = (UBYTE)(rand()>>24) + 0;
  948.  
  949.                                                 MidRdst[2] = (UBYTE)(rand()>>24) + 0;
  950.                                                 MidGdst[2] = (UBYTE)(rand()>>24) + 0;
  951.                                                 MidBdst[2] = (UBYTE)(rand()>>24) + 0;
  952.                                         break;
  953.  
  954.                                         case 2:
  955.                                                 MidRdst[0] = (UBYTE)(rand()>>24) + 0;
  956.                                                 MidGdst[0] = (UBYTE)(rand()>>24) + 0;
  957.                                                 MidBdst[0] = (UBYTE)(rand()>>24) + 0;
  958.  
  959.                                                 MidRdst[1] = (UBYTE)(rand()>>24) + 0;
  960.                                                 MidGdst[1] = (UBYTE)(rand()>>24) + 0;
  961.                                                 MidBdst[1] = (UBYTE)(rand()>>24) + 0;
  962.  
  963.                                                 MidRdst[2] = (UBYTE)(rand()>>24) + 0;
  964.                                                 MidGdst[2] = (UBYTE)(rand()>>24) + 0;
  965.                                                 MidBdst[2] = (UBYTE)(rand()>>24) + 0;
  966.                                         break;
  967.  
  968.                                         case 3:
  969.                                                 MidRdst[0] = (UBYTE)(rand()>>25) + 0;
  970.                                                 MidGdst[0] = (UBYTE)(rand()>>25) + 0;
  971.                                                 MidBdst[0] = (UBYTE)(rand()>>25) + 0;
  972.  
  973.                                                 MidRdst[1] = (UBYTE)(rand()>>24) + 0;
  974.                                                 MidGdst[1] = (UBYTE)(rand()>>24) + 0;
  975.                                                 MidBdst[1] = (UBYTE)(rand()>>24) + 0;
  976.  
  977.                                                 MidRdst[2] = (UBYTE)(rand()>>24) + 0;
  978.                                                 MidGdst[2] = (UBYTE)(rand()>>24) + 0;
  979.                                                 MidBdst[2] = (UBYTE)(rand()>>24) + 0;
  980.                                         break;
  981.  
  982.                                         default:
  983.                                                 MidRdst[0] = (UBYTE)(rand()>>25) + 127;
  984.                                                 MidGdst[0] = (UBYTE)(rand()>>25) + 127;
  985.                                                 MidBdst[0] = (UBYTE)(rand()>>25) + 127;
  986.  
  987.                                                 MidRdst[1] = (UBYTE)(rand()>>25) + 64;
  988.                                                 MidGdst[1] = (UBYTE)(rand()>>25) + 64;
  989.                                                 MidBdst[1] = (UBYTE)(rand()>>25) + 64;
  990.  
  991.                                                 MidRdst[2] = (UBYTE)(rand()>>25) + 32;
  992.                                                 MidGdst[2] = (UBYTE)(rand()>>25) + 32;
  993.                                                 MidBdst[2] = (UBYTE)(rand()>>25) + 32;
  994.                                         break;
  995.                                 }
  996. #endif
  997.                         }
  998.  
  999.                         CalcLine(Zoom2, Width, Height, FieldToCalc);
  1000.                         LineToCalc++;
  1001.                         if(LineToCalc > Height-1) LineToCalc = Height-1;
  1002.                         FrameCountField++;
  1003.                         
  1004.                         if(FrameCountField > 500) {
  1005.  
  1006.                         printf("FCF 500\n");
  1007.                                 FrameCountField=0;
  1008.  
  1009.                                 LineToCalc = 1;
  1010.                                 PrevField = FieldToCalc;
  1011.  
  1012. #ifdef __VBCC__
  1013.                                 do {
  1014.                         FieldToCalc=(UBYTE)(rand() % NUMFIELDS);
  1015.                                 } while (FieldToCalc == PrevField);
  1016.  
  1017. /*                              if(FieldToCalc == 0)
  1018.                                 FieldToCalc = 1;
  1019.                                 else if(FieldToCalc == 1)
  1020.                                 FieldToCalc = 2;
  1021.                                 else if(FieldToCalc == 2)
  1022.                                 FieldToCalc = 3;
  1023.                                 else if(FieldToCalc == 3)
  1024.                                 FieldToCalc = 4;
  1025.                                 else if(FieldToCalc == 4)
  1026.                                 FieldToCalc = 6;
  1027.                                 else if(FieldToCalc == 6)
  1028.                                 FieldToCalc = 7;
  1029.                                 else if(FieldToCalc == 7)
  1030.                                 FieldToCalc = 9;
  1031.                                 else if(FieldToCalc == 9)
  1032.                                 FieldToCalc = 10;
  1033.                                 else if(FieldToCalc == 10)
  1034.                                 FieldToCalc = 13;
  1035.                                 else if(FieldToCalc == 13)
  1036.                                 FieldToCalc = 14;
  1037.                                 else if(FieldToCalc == 14)
  1038.                                 FieldToCalc = 15;
  1039.                                 else if(FieldToCalc == 15)
  1040.                                 FieldToCalc = 16;
  1041.                                 else if(FieldToCalc == 16)
  1042.                                 FieldToCalc = 18;
  1043.                                 else
  1044.                                 FieldToCalc = 0;
  1045. */
  1046. #endif
  1047.  
  1048. #ifndef __VBCC__
  1049.                                 do {
  1050.                         FieldToCalc=(UBYTE)(rand()>>24) % NUMFIELDS;
  1051.                                 } while (FieldToCalc == PrevField);
  1052. #endif
  1053.  
  1054.                                 for(j=0; j<Width*Height; j++)
  1055.                                 {
  1056.                                         Zoom[j]=Zoom2[j];
  1057.                                 }
  1058.                                 printf("preparing field %d\n", FieldToCalc);
  1059.                                 PrepareConstants(FieldToCalc);
  1060.  
  1061.                         }
  1062.  
  1063.                         for(i=Width*Cutoff; i<Width*(Height-Cutoff); i++) {
  1064.                                 PixelC[i]=PixelD[Zoom[i]];
  1065.                         }
  1066.  
  1067.  
  1068.                         /* Make a backup of the data pointers */
  1069.                         PluginRawL    = SpecRawL;
  1070.                         PluginRawR    = SpecRawR;
  1071.                         PluginSamples = SampleRaw;
  1072.  
  1073.                         InfoCount++;
  1074.                         if(InfoCount < 75) MakeTitle();
  1075.                         else InfoCount=75;
  1076.  
  1077.                         TimeWave++;
  1078.                         FrameCountWave++;
  1079.                         CalcWave(WaveToCalc0, 0);
  1080.                         DrawWave(WaveX,  WaveY,  Width, Height, WaveToCalc0, 0);
  1081.                         CalcWave(WaveToCalc1, 1);
  1082.                         DrawWave(WaveX2, WaveY2, Width, Height, WaveToCalc1, 1);
  1083.                         if(FrameCountWave > 200) {
  1084.  
  1085.                                 if(DestWaveBuffer == 1) WaveMorph += 0.015; //was 0.005
  1086.                                 else                    WaveMorph -= 0.015; //was 0.005
  1087.                         }
  1088.                         if (WaveMorph > 1.0) WaveMorph = 1.0;
  1089.                         if (WaveMorph < 0.0) WaveMorph = 0.0;
  1090.  
  1091.                         if(FrameCountWave > 400) {
  1092.                         printf("FCW 400\n");
  1093.                         FrameCountWave = 0;
  1094.                         DestWaveBuffer = 1 - DestWaveBuffer;
  1095. #ifdef __VBCC__
  1096.                                 do {
  1097.                                         WaveToCalc = (UBYTE)(rand() % NUMWAVES);
  1098.                                 } while (WaveToCalc == WaveToCalc0 || WaveToCalc == WaveToCalc1 || WaveToCalc == 10 || WaveToCalc == 8 || WaveToCalc == 6);
  1099.  
  1100.                                 if(DestWaveBuffer) {
  1101.                                         WaveToCalc1 = WaveToCalc;
  1102.                                         InitWave(WaveToCalc1, 1);
  1103.                                 }
  1104.                                 else {
  1105.                                         WaveToCalc0 = WaveToCalc;
  1106.                                         InitWave(WaveToCalc0, 0);
  1107.                                 }
  1108.  
  1109. /*
  1110. if (WaveToCalc1 == 1)
  1111. WaveToCalc1 = 5;
  1112. else if (WaveToCalc1 == 2)
  1113. WaveToCalc1 = 7;
  1114. else if (WaveToCalc1 == 3)
  1115. WaveToCalc1 = 11;
  1116. else if (WaveToCalc1 == 4)
  1117. WaveToCalc1 = 1;
  1118. else if (WaveToCalc1 == 5)
  1119. WaveToCalc1 = 2;
  1120. else if (WaveToCalc1 == 7)
  1121. WaveToCalc1 = 3;
  1122. else
  1123. WaveToCalc1 = 4;
  1124.  
  1125. WaveToCalc0 = 0;
  1126.  
  1127.         InitWave(WaveToCalc1, 1);
  1128.         printf("initializing wave %d\n",WaveToCalc1);
  1129.         InitWave(WaveToCalc0, 0);
  1130. */
  1131. #endif
  1132.  
  1133. #ifndef __VBCC__
  1134.                                 do {
  1135.                                         WaveToCalc = (UBYTE)(rand()>>24) % NUMWAVES;
  1136.                                         WaveToCalc = NUMWAVES-1;
  1137.                                 } while (WaveToCalc == WaveToCalc0 || WaveToCalc == WaveToCalc1);
  1138.  
  1139.                                 if(DestWaveBuffer) {
  1140.                                         WaveToCalc1 = WaveToCalc;
  1141.                                         InitWave(WaveToCalc1, 1);
  1142.                                 }
  1143.                                 else {
  1144.                                         WaveToCalc0 = WaveToCalc;
  1145.                                         InitWave(WaveToCalc0, 0);
  1146.                                 }
  1147. #endif
  1148.                         }
  1149.  
  1150.                         for(i=0; i<Width*2; i++) {
  1151.                                 float xf,yf;
  1152.                                 ULONG x,y;
  1153.                                 xf = (float)WaveX[i]*(1.0-WaveMorph) + (float)WaveX2[i]*(WaveMorph);
  1154.                                 yf = (float)WaveY[i]*(1.0-WaveMorph) + (float)WaveY2[i]*(WaveMorph);
  1155.                                 x  = (ULONG)xf + Width/2;
  1156.                                 y  = (ULONG)yf + Height/2;
  1157.                                 if(x < Width-1) {
  1158.                                         if(y < Height-1) {
  1159.                                                 if(x > 0) {
  1160.                                                         if(y > 0) {
  1161.                                                                 ActPixel = PixelC + y * Width + x;
  1162.                                                                 *ActPixel=255;
  1163.                                                         }
  1164.                                                 }
  1165.                                         }
  1166.                                 }
  1167.                         }
  1168.  
  1169.                         SetAPen(rp, 0);
  1170. /*                      if(ShowWave) WritePixelArray(PixelC, 1, Cutoff+1, Width, rp, 0, Cutoff+1, Width-2, Height-2*Cutoff-2, RECTFMT_LUT8);
  1171.                         else         WritePixelArray(PixelD, 1, Cutoff+1, Width, rp, 0, Cutoff+1, Width-2, Height-2*Cutoff-2, RECTFMT_LUT8);
  1172.                         RectFill(rp, 0, 0, Width, Cutoff);
  1173.                         RectFill(rp, 0, Height-Cutoff-1, Width, Height-1);
  1174. */
  1175.                         if(ShowWave) WritePixelArray(PixelC, 1, Cutoff+1, Width, rp, Woffset, Cutoff+1, Width-2, Height-2*Cutoff-2, RECTFMT_LUT8);
  1176.                         else         WritePixelArray(PixelD, 1, Cutoff+1, Width, rp, Woffset, Cutoff+1, Width-2, Height-2*Cutoff-2, RECTFMT_LUT8);
  1177.                         RectFill(rp, 0, 0, Width, Cutoff);
  1178.                         RectFill(rp, 0, Height-Cutoff-1, Width, Height-1);
  1179.  
  1180.  
  1181.  
  1182.  
  1183.                         if(DisplayFPS)
  1184.                         {
  1185.                                 Move(rp, 0, 15);
  1186.                                 SetABPenDrMd(rp, 255, 0, JAM2);
  1187.                                 sprintf(FPStext, "%3ld fps       ", 5*eclock/itime);
  1188.                                 Text(rp, FPStext, 7);
  1189.                         }
  1190.                 }
  1191.         }
  1192. }
  1193.  
  1194.  
  1195.  
  1196. void Blur(UBYTE *PixelC, UBYTE *PixelD) {
  1197.   UBYTE *ActPixel;
  1198.   UBYTE *DstPixel;
  1199.   UBYTE *AbovePixel, *BelowPixel;
  1200.   UBYTE Left, Act, Right;
  1201.   WORD w;
  1202.   ULONG i;
  1203.  
  1204.         PixelC += Width*Cutoff;
  1205.         PixelD += Width*Cutoff;
  1206.  
  1207.   ActPixel   = PixelC+Width+1;
  1208.   AbovePixel = ActPixel-Width;
  1209.   BelowPixel = ActPixel+Width;
  1210.   DstPixel   = PixelD+Width+1;
  1211.  
  1212.   Left  = 0;
  1213.   Act   = 0;
  1214.   Right = 0;
  1215.  
  1216.         for(i=Width*(Cutoff+1); i<(Width*(Height-Cutoff-2)-2); i++) {
  1217.     Right = *(ActPixel+1);
  1218.  
  1219.     w = (Right + Act + Left + *AbovePixel + *BelowPixel) * 3 / 16;
  1220.                 if(w<0) w=0;
  1221.     *DstPixel++ = w;
  1222.  
  1223.     ActPixel++;
  1224.     AbovePixel++;
  1225.     BelowPixel++;
  1226.  
  1227.     Left = Act;
  1228.     Act = Right;
  1229.   }
  1230. }
  1231.  
  1232. void ShowRequester(char *Text, char *Button) {
  1233.         struct EasyStruct Req;
  1234.         Req.es_StructSize   = sizeof(struct EasyStruct);
  1235.         Req.es_Flags        = 0;
  1236.   Req.es_Title        = "AmigaAMP Plugin";
  1237.   Req.es_TextFormat   = (UBYTE*)Text;
  1238.   Req.es_GadgetFormat = (UBYTE*)Button;
  1239.         EasyRequestArgs(NULL, &Req, NULL, NULL);
  1240. }
  1241.  
  1242. BOOL OpenTimer(void) {
  1243.         struct EClockVal ev = {0,0};
  1244.  
  1245.         if(TimerMP=(struct MsgPort*)CreatePort(0,0)) {
  1246.                 if(TimerIO=(struct timerequest *)CreateIORequest(TimerMP, sizeof(struct timerequest))) {
  1247.                         TimerError=OpenDevice("timer.device", UNIT_ECLOCK, (struct IORequest *)TimerIO, 0);
  1248.                         if(TimerError==0) {
  1249.  
  1250.                                 TimerBase = (struct Library*) &TimerIO->tr_node.io_Device->dd_Library;
  1251.                                 EFreq=ReadEClock(&ev);
  1252.  
  1253.                                 TimerMask = 1L << TimerMP->mp_SigBit;
  1254.  
  1255.                                 return(TRUE);
  1256.                         }
  1257.                 }
  1258.         }
  1259.         return(FALSE);
  1260. }
  1261.  
  1262. void CloseTimer(void) {
  1263.         if(!TimerError)   CloseDevice((struct IORequest *)TimerIO);
  1264.         if(TimerIO)       DeleteIORequest(TimerIO);
  1265.         if(TimerMP)       DeletePort(TimerMP);
  1266. }
  1267.  
  1268. void StartTimer(void) {
  1269.         TimerIO->tr_node.io_Command = TR_ADDREQUEST;
  1270.         TimerIO->tr_node.io_Flags   = 0;
  1271.         TimerIO->tr_time.tv_secs    = 0;
  1272.         TimerIO->tr_time.tv_micro   = EFreq/LimitFPS;
  1273.         SendIO((struct IORequest *)TimerIO);
  1274. }
  1275.  
  1276. struct MsgPort *MyCreatePort(UBYTE *name, LONG pri) {
  1277.         int sigBit;
  1278.         struct MsgPort *mp;
  1279.  
  1280.         if((sigBit = AllocSignal(-1L)) == -1)   return(NULL);
  1281.  
  1282.         mp = (struct MsgPort*) AllocVec(sizeof(struct MsgPort), MEMF_PUBLIC|MEMF_CLEAR);
  1283.  
  1284.         if(!mp) {
  1285.                 FreeSignal(sigBit);
  1286.                 return(NULL);
  1287.         }
  1288.  
  1289.         mp->mp_Node.ln_Name = name;
  1290.         mp->mp_Node.ln_Pri  = pri;
  1291.         mp->mp_Node.ln_Type = NT_MSGPORT;
  1292.         mp->mp_Flags        = PA_SIGNAL;
  1293.         mp->mp_SigBit       = sigBit;
  1294.         mp->mp_SigTask      = FindTask(NULL);
  1295.         if(name) AddPort(mp);
  1296.         #if defined (__SASC) || defined (__VBCC__)
  1297.                 else NewList(&(mp->mp_MsgList));
  1298.         #else
  1299.                 else NewListPPC(&(mp->mp_MsgList));
  1300.         #endif
  1301.  
  1302.         return(mp);
  1303. }
  1304.  
  1305. void MyDeletePort(struct MsgPort *mp) {
  1306.         if(mp->mp_Node.ln_Name) RemPort(mp);
  1307.         mp->mp_SigTask         = (struct Task *) -1;
  1308.         mp->mp_MsgList.lh_Head = (struct Node *) -1;
  1309.         FreeSignal(mp->mp_SigBit);
  1310.         FreeVec(mp); mp=NULL;
  1311. }
  1312.  
  1313. void InitField(LONG *Zoom, ULONG Width, ULONG Height) {
  1314.         LONG i,xs,ys,xd,yd;
  1315.  
  1316.         float scale,greater;
  1317.         float xsf,ysf,xdf,ydf;
  1318.         float rsf,tsf,rdf,tdf;
  1319.         float wf,hf;
  1320.  
  1321.         wf=(float)Width;
  1322.         hf=(float)Height;
  1323.  
  1324.         greater=1.0;
  1325.         if(wf > greater) greater = wf;
  1326.         if(hf > greater) greater = hf;
  1327.  
  1328.         scale = 1.0 / (greater/2.0);
  1329.  
  1330.         for(yd=0; yd<(Height); yd++) {
  1331.                 for(xd=0; xd<(Width); xd++) {
  1332.                         xdf = (xd - wf/2.0) * scale;
  1333.                         ydf = (yd - hf/2.0) * scale;
  1334.  
  1335.                         xsf = xdf - xdf * 0.075;
  1336.                         ysf = ydf - ydf * 0.075;
  1337.  
  1338.                         xs = xsf/scale + wf/2.0;
  1339.                         ys = ysf/scale + hf/2.0;
  1340.  
  1341.                         if(xs < Width/2)  xs++;
  1342.                         if(ys < Height/2) ys++;
  1343.  
  1344.                         if(xs < 0)      xs = 0;
  1345.                         if(xs > Width)  xs = Width;
  1346.                         if(ys < 0)      ys = 0;
  1347.                         if(ys > Height) ys = Height;
  1348.  
  1349.                         Zoom[Width * yd + xd] = Width * ys + xs;
  1350.                 }
  1351.         }
  1352. }
  1353.  
  1354.  
  1355. void MakeCMap(void) {
  1356.         int j,i,c;
  1357.         float r,g,b;
  1358.         float rs,gs,bs;
  1359.  
  1360.         r=255; g=255; b=255;
  1361.  
  1362.         c=255;
  1363.  
  1364.         Colour[0]=256L<<16+0;
  1365.  
  1366.         for(j=0; j<4; j++) {
  1367.                 rs = (r - (float)MidR[j]) / 64.0;
  1368.                 gs = (g - (float)MidG[j]) / 64.0;
  1369.                 bs = (b - (float)MidB[j]) / 64.0;
  1370.                 for(i=0; i<64; i++) {
  1371.                         Colour[1+3*c+0] = (ULONG)r << 24;
  1372.                         Colour[1+3*c+1] = (ULONG)g << 24;
  1373.                         Colour[1+3*c+2] = (ULONG)b << 24;
  1374.                         r -= rs;
  1375.                         g -= gs;
  1376.                         b -= bs;
  1377.                         c--;
  1378.                 }
  1379.         }
  1380.  
  1381. }
  1382.  
  1383. void MakeTitle(void) {
  1384.         long x,y,i,p,s,v,xs,ys;
  1385.         UWORD Blt1[27] = {
  1386.                 0x7008,0x0000,0x0000,0x8808,0x0000,0x0000,0x822B,0x1963,
  1387.                 0x8E38,0x722C,0xA590,0x5144,0x0A28,0x9913,0xD07C,0x8A28,
  1388.                 0x8514,0x5040,0x8A68,0xA594,0xD144,0x71AF,0x1963,0x4E38,
  1389.                 0x0000,0x0100,0x0000
  1390.         }; // W=46, H=9
  1391.         UWORD Blt2[54] = {
  1392.                 0x8001,0xF400,0x0000,0x0101,0x0000,0x0080,0x8000,0x4400,
  1393.                 0x0000,0x0111,0x0000,0x0080,0xB220,0x458E,0x7638,0xC111,
  1394.                 0x3967,0x9C80,0xCA20,0x4651,0x4905,0x2092,0x4590,0xA280,
  1395.                 0x8940,0x4451,0x493C,0xC0AA,0x7D11,0x3E80,0x8940,0x4451,
  1396.                 0x4944,0x20AA,0x4112,0x2080,0x8880,0x4451,0x494D,0x2044,
  1397.                 0x4514,0x2280,0xF080,0x444E,0x4934,0xC044,0x3917,0x9C80,
  1398.                 0x0100,0x0000,0x0000,0x0000,0x0000,0x0000
  1399.         }; // W=89, H=9
  1400.  
  1401.         xs = (Width-46)/2;
  1402.         ys = Height/2-30-9;
  1403.         s=0;
  1404.         for(y=0; y<9; y++) {
  1405.                 x=0;
  1406.                 for(i=0; i<3; i++) {
  1407.                         for(p=0; p<16; p++) {
  1408.                                 x++;
  1409.                                 v = Blt1[s] & (1<<(15-p));
  1410.                                 if(v) PixelC[(ys+y)*Width+xs+x] = 255;
  1411.                         }
  1412.                         s++;
  1413.                 }
  1414.         }
  1415.         xs = (Width-89)/2;
  1416.         ys = Height/2+30;
  1417.         s=0;
  1418.         for(y=0; y<9; y++) {
  1419.                 x=0;
  1420.                 for(i=0; i<6; i++) {
  1421.                         for(p=0; p<16; p++) {
  1422.                                 x++;
  1423.                                 v = Blt2[s] & (1<<(15-p));
  1424.                                 if(v) PixelC[(ys+y)*Width+xs+x] = 255;
  1425.                         }
  1426.                         s++;
  1427.                 }
  1428.         }
  1429. }
  1430.  
  1431.  
  1432. void ReColor(void) {
  1433. #ifndef __VBCC__
  1434.  
  1435.         int i;
  1436.         for(i=0; i<3; i++) {
  1437.                 if(MidR[i] > MidRdst[i]) MidR[i] --;
  1438.                 if(MidG[i] > MidGdst[i]) MidG[i] --;
  1439.                 if(MidB[i] > MidBdst[i]) MidB[i] --;
  1440.                 if(MidR[i] < MidRdst[i]) MidR[i] ++;
  1441.                 if(MidG[i] < MidGdst[i]) MidG[i] ++;
  1442.                 if(MidB[i] < MidBdst[i]) MidB[i] ++;
  1443.  
  1444.         }
  1445. #endif
  1446.         MakeCMap();
  1447.         LoadRGB32(&PluginScreen->ViewPort, Colour);
  1448. }
  1449.  
  1450. float rnd(float max) {
  1451.         ULONG r;
  1452.         ULONG m;
  1453.  
  1454.         m = (ULONG)(max * 10000.0);
  1455. #ifndef __VBCC__
  1456.         r=(rand()>>8) % m;
  1457. #else
  1458.         r=(rand() % m);
  1459. #endif
  1460.         return (float)r/10000.0;
  1461. }
  1462.  
  1463. float sgn(float val) {
  1464.         if(val > 0.0) return  1.0;
  1465.         if(val < 0.0) return -1.0;
  1466.         return 0.0;
  1467. }
  1468.  
  1469. float trnc(float value) {
  1470.         return ceil(value);
  1471. }
  1472.  
  1473. #ifdef __SASC
  1474. void SetPriority(void) {
  1475.         struct TagItem MyTags[2];
  1476.         if(PPCLibBase=OpenLibrary("ppc.library",0)) {
  1477.                 MyTags[0].ti_Tag  = PPCTASKTAG_PRIORITY;
  1478.                 MyTags[0].ti_Data = 15;
  1479.                 MyTags[1].ti_Tag         = TAG_END;
  1480.                 CloseLibrary(PPCLibBase);
  1481.         }
  1482. }
  1483. #endif
  1484.  
  1485.  
  1486.  
  1487.  
  1488.  
  1489.  
  1490.